package com.project.personalfundmanager.client;

import java.util.Arrays;

import com.extjs.gxt.ui.client.Style.HorizontalAlignment;
import com.extjs.gxt.ui.client.event.ButtonEvent;
import com.extjs.gxt.ui.client.event.SelectionListener;
import com.extjs.gxt.ui.client.widget.Window;
import com.extjs.gxt.ui.client.widget.button.Button;
import com.extjs.gxt.ui.client.widget.button.ButtonBar;
import com.extjs.gxt.ui.client.widget.form.ComboBox;
import com.extjs.gxt.ui.client.widget.layout.FormLayout;
import com.project.personalfundmanager.client.common.UIHelper;
import com.project.personalfundmanager.client.listeners.SlabInfoListener;
import com.project.personalfundmanager.shared.models.StringWrapperModel;

public class SlabInfoWindow extends Window
{
	private ComboBox<StringWrapperModel> womanCombo;
	private ComboBox<StringWrapperModel> scCombo;
	private SlabInfoListener listener;

	public SlabInfoWindow(final SlabInfoListener listener)
	{
		this.listener = listener;
		initWindow();
		StringWrapperModel[] values = new StringWrapperModel[]{ new StringWrapperModel("No"), new StringWrapperModel("Yes") };
		womanCombo = new UIHelper( null ).getCombobox( Arrays.asList( values ), "woman", "Are you woman ?", true );
		scCombo = new UIHelper( null ).getCombobox( Arrays.asList( values ), "woman", "Are you senior citizen ?", true );
		add( womanCombo );
		add( scCombo );
		initButtons();
		show();
	}
	
	
	void initButtons()
	{
		ButtonBar bar = new ButtonBar();
		bar.add( new Button("Back", new SelectionListener<ButtonEvent>(){
			public void componentSelected( ButtonEvent ce )
			{
				hide();
				listener.back();
			}
		}));
		
		bar.add(new Button( "Continue", new SelectionListener<ButtonEvent>()
		{
			public void componentSelected( ButtonEvent ce )
			{
				if(womanCombo.getValue() == null)
				{
					womanCombo.markInvalid( "This field is mandatory." );
					return;
				}
				
				if(scCombo.getValue() == null)
				{
					scCombo.markInvalid( "This field is mandatory." );
					return;
				}
				
				boolean isWoman = womanCombo.getValue().getValue().equals( "Yes" ) ? true : false;
				boolean isSc = scCombo.getValue().getValue().equals( "Yes" ) ? true : false;
				hide();
				listener.goAhead(isWoman, isSc);
			}
		} ));
		
		fbar.setAlignment( HorizontalAlignment.CENTER );
		fbar = bar;
	}
	
	private void initWindow()
	{
		FormLayout layout = new FormLayout();
		layout.setLabelWidth( 175 );
		setLayout( layout );
		setClosable( false );
		setWidth( 400 );
	}
}
